---
slug: /ci/integrations/google-cloud-run
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# Google Cloud Run

Dagger can be used to deploy any containerized application to Google Cloud Run. This allows developers to create continuous delivery pipelines that can be used both locally and in CI, and also run faster due to Dagger's intelligent caching. This integration does not require any installation of Google Cloud tools, such as the Google Cloud CLI or the Google Cloud SDKs.

## How it works

The integration depends on the [`google-cloud-run` Dagger module](https://daggerverse.dev/mod/github.com/vvaswani/daggerverse/google-cloud-run@6e44ee4a901dda7d742574354132745701db3c52), which provides various Dagger Functions to create or update a Google Cloud Run service using a container image. These Dagger Functions make it easy to extend existing CI pipelines with additional deployment support.

To use this integration, you can call the Dagger module with the Dagger CLI directly, or you can create your own Dagger Function that uses it. In the latter case, you must:

- Create a new Dagger module in your project
- Install the `google-cloud-run` Dagger module as a dependency
- Implement your CI/CD pipeline as one or more Dagger Function(s)
- Test your Dagger Function(s) locally and then transfer them to your CI/CD environment

## Prerequisites

- The [`google-cloud-run` Dagger module](https://daggerverse.dev/mod/github.com/vvaswani/daggerverse/google-cloud-run@6e44ee4a901dda7d742574354132745701db3c52)
- An active Google Cloud project with the Google Cloud APIs and the Google Cloud Run Admin API enabled
- An active Google Cloud service account for the target project with Editor, Service Account Token Creator, and Cloud Run Admin roles
- A JSON keyfile with credentials for the target service account
- The address of the container image to be deployed

## Example

The following example demonstrates how to deploy a containerized application on Google Cloud Run using this integration.

The simplest option is to use the Dagger CLI to directly call the Dagger Function. Remember to update the `project`, `location`, `image`, `http-port` and `credential` arguments with the correct values and filesystem path.

```shell
dagger -m github.com/vvaswani/daggerverse/google-cloud-run@v0.1.5 call create-service \
  --project=my-project \
  --location=us-central1 \
  --image=us-docker.pkg.dev/cloudrun/container/hello \
  --http-port=3000 \
  --credential=file://my-keyfile.json
```

If your requirements are more complex - for example, if you already have one or more Dagger Functions to build, test and containerize your application - you can install the `google-cloud-run` module as a dependency and call it from your existing Dagger Functions using code.

<Tabs groupId="language">
<TabItem value="Go">
Create a new Dagger module:

```shell
dagger init --name=my-module --sdk=go --source=./dagger
```

Install the Google Cloud Run module from the Daggerverse:

```shell
dagger install github.com/vvaswani/daggerverse/google-cloud-run@v0.1.5
```

Update the generated `dagger/main.go` file with the following code:

```go file=./snippets/google-cloud-run/go/main.go
```
</TabItem>
<TabItem value="Python">
Create a new Dagger module:

```shell
dagger init --name=my-module --sdk=python --source=./dagger
```

Install the Google Cloud Run module from the Daggerverse:

```shell
dagger install github.com/vvaswani/daggerverse/google-cloud-run@v0.1.5
```

Update the generated `dagger/src/my_module/main.py` file with the following code.

```python file=./snippets/google-cloud-run/python/main.py
```
</TabItem>
<TabItem value="TypeScript">
Create a new Dagger module:

```shell
dagger init --name=my-module --sdk=typescript --source=./dagger
```

Install the Google Cloud Run module:

```shell
dagger install github.com/vvaswani/daggerverse/google-cloud-run@v0.1.5
```

Update the generated `dagger/src/index.ts` file with the following code:

```typescript file=./snippets/google-cloud-run/typescript/index.ts
```
</TabItem>
</Tabs>

:::warning
The code sample above is illustrative only. Modify it to your application's specific requirements.
:::

Here is an example of calling the Dagger Function to deploy the Google Cloud sample application to Google Cloud Run. Remember to update the `project-name`, `service-location`, `image-address` and `credential` arguments with the correct values and filesystem path.

```shell
dagger call deploy \
  --project-name=my-project \
  --service-location=us-central1 \
  --image-address=us-docker.pkg.dev/cloudrun/container/hello \
  --service-port=3000 \
  --credential=file://my-keyfile.json
```

:::tip
The `google-cloud-run` Dagger module can also modify an existing service by deploying a new container image to the service URL.
:::

## Resources

If you have any questions about additional ways to use Google Cloud Run with Dagger, join our [Discord](https://discord.gg/dagger-io) and ask your questions in our [help channel](https://discord.com/channels/707636530424053791/1030538312508776540).

## About Google Cloud Run

[Google Cloud Run](https://cloud.google.com/run) is a managed service to run containerized applications using Google Cloud.
